package com.fish.start.animation.effect;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.util.Log;

import com.fish.start.animation.AnimationSet;
import com.fish.start.animation.Attr.BitmapWay;
import com.fish.start.animation.views.FishView;

public class BitmapWayEffect extends BitmapWay{
	private static final String tag = BitmapWayEffect.class.getSimpleName();
	public BitmapWayEffect(FishView aFishView,Bitmap aBitmap){
		super(aFishView,aBitmap); 
	}
	@Override
	public void draw(Canvas aCanvas){
		if(mBitmap==null)return ;
		matrix.postTranslate(mx-(float)mow/2, my-(float)moh/2);
		if(rotate!=null){
			aCanvas.rotate(rotate.from, mx, my);
		}
		aCanvas.drawBitmap(mBitmap, mx-(float)mow/2, my-(float)moh/2,mPaint);
	}
	
	public Object clone() { 
		Object o = null;
		o = super.clone();
		return o;
	}
	@Override
	public void createAnimatons(AnimationSet mAnimations) throws CloneNotSupportedException {
		setPosition();
		dt = 0.0f;
		while(!mAnimations.mStopProduce){
			dt += TIME_SPANE;
			boolean fAlpha = alpha();
			boolean fDis = displacement();
			boolean fRotate = rotate();
			boolean fScale = scale();
			if(null!=scale){
				mow = Math.round(oOldw*scale.from)<=0?1:Math.round(oOldw*scale.from);
				moh = Math.round(oOldh*scale.from)<=0?1:Math.round(oOldh*scale.from);
				mBitmap = Bitmap.createScaledBitmap(oldBitmap,mow, moh,true);
			}
			//Log.d(tag, "create--->scale.from:"+scale.from+",mow="+mow+",moh="+moh);
			if(displacement!=null){
				mx = displacement.fromX ;
				my = displacement.fromY ;
			}
			//Log.d(tag, "my and mx,"+scale.from+",mx="+mx+",my="+my);
			if(rotate != null){
				//Log.d(tag, "rotate info:degreefrom="+rotate.from+",degreeto="+rotate.to);
				Log.d(tag, "rotate info:px="+rotate.px+",py="+rotate.py);
			}

			mAnimations.push((BitmapWayEffect)this.clone());
			
			if(fAlpha && fDis && fRotate && fScale){
				break;
			}
		}
	}
}
